package com.jackrain.nea.omslocal.task;

import com.jackrain.nea.config.PropertiesConf;
import com.jackrain.nea.omslocal.service.ChangeQtyStatusService;
import com.jackrain.nea.omslocal.service.QuantityQueryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * @Discription:  自动扫描 库存异动表的过期数据, 更新状态
 *
 * Created with IntelliJ IDEA.
 *
 * @Author cs
 * @Date 2017/7/10 9:31
 */
@Component
@Slf4j
public class AutoChangeQtyStatus {



    @Autowired
    private ChangeQtyStatusService changeQtyStatusService;
    @Autowired
    private PropertiesConf pconf;

    public void getScheduledExecutor() {

        log.info("AutoMotThreads ChangeQTYStatus started !!!");
        Runnable runnable = new Runnable() {

            public void run() {
                try {
                    changeQtyStatusService.changeStatusTimeOut();
                    changeQtyStatusService.changeStatusErro();
                } catch (Exception e) {
                    e.printStackTrace();
                    // 执行任务错误,将日志记录
                }
            }
        };
        ScheduledExecutorService service = Executors
                .newSingleThreadScheduledExecutor();
        // 第二个参数为首次执行的延时时间，第三个参数为定时执行的间隔时间
        // 正式 要延迟适当时间,以便时间初始化赋值
        service.scheduleAtFixedRate(runnable, 5,pconf.getPropertyInt("ons.errotime") , TimeUnit.MINUTES);
    }
}
